package com.hexb.smh.aop;

import com.hexb.smh.entity.enums.ILogCreator;
import com.hexb.smh.entity.enums.Operators;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author : hexb
 * 用于产生特定的操作日志
 */
@Service
public class OperationLogFactory {
    private Map<Operators, ILogCreator> map = new ConcurrentHashMap<>();

    public void register(Operators op, ILogCreator creator) {
        map.put(op, creator);
    }

    public ILogCreator get(Operators op) {
        ILogCreator logCreator = map.get(op);
        return logCreator == null ? op.getCreator() : logCreator;
    }
}
